#include "Room.h"
int totalRooms = tot;

bool randomBool() {
	return rand() % 2 == 1;
}
s
Room::Room(int mapArray[tot * 2][tot * 2]) {
	xPos = tot;
	yPos = tot;
	loot = 0;
	enemy = 0;
	mapArray[xPos][yPos] = totalRooms;
	northDoor = false;
	southDoor = false;
	eastDoor = false;
	westDoor = false;
	
	std::cout << totalRooms;
	std::cout << " ";
	int roomLayout = rand() % 15 | rand() % 15;

	if (roomLayout & 1 && totalRooms > 0) {
		totalRooms--;
		north = new Room(xPos, yPos + 1, 0, north, mapArray);
		northDoor = true;
	}
	if (roomLayout & 2 && totalRooms > 0) {
		totalRooms--;
		east = new Room(xPos + 1, yPos, 1, east, mapArray);
		eastDoor = true;
	}
	if (roomLayout & 4 && totalRooms > 0) {
		totalRooms--;
		south = new Room(xPos, yPos - 1, 2, south, mapArray);
		southDoor = true;
	}
	if (roomLayout & 8 && totalRooms > 0) {
		totalRooms--;
		west = new Room(xPos - 1, yPos, 3, west, mapArray);
		westDoor = true;

	}
	else {
		north = new Room(xPos, yPos + 1, 0, north, mapArray);
		totalRooms--;
		northDoor = true;
	}
}

Room::Room(int prevX, int prevY, int prevDoorLoc, Room* prevDoor, int mapArray[tot * 2][tot * 2]) {
	//prevDoorLoc meaning 0 north door, 1 east door, 2 south door, 3 west door
	xPos = prevX;
	yPos = prevY;
	loot = 0;
	enemy = 0;
	northDoor = false;
	southDoor = false;
	eastDoor = false;
	westDoor = false;

	int roomLayout = rand() % 15;
	mapArray[(int)xPos][(int)yPos] = totalRooms;

	if (totalRooms > tot / 2 && (roomLayout == 0|| roomLayout == 1 || roomLayout == 2|| roomLayout == 4|| roomLayout == 8)){
		roomLayout = roomLayout | rand() % 15;
	}
	

	if (prevDoorLoc == 0) {
		southDoor = true;
		south = prevDoor;
	}
	if (prevDoorLoc == 1) {
		westDoor = true;
		west = prevDoor;
	}
	if (prevDoorLoc == 2) {
		northDoor = true;
		north = prevDoor;
	}
	if (prevDoorLoc == 3) {
		eastDoor = true;
		east = prevDoor;
	}

	std::cout << totalRooms;
	std::cout << " ";

	if (roomLayout & 1 && totalRooms > 0 && !northDoor) {
		
		totalRooms--;
		north = new Room(xPos, yPos + 1, 0, north, mapArray);
		northDoor = true;
	}
	if (roomLayout & 2 && totalRooms > 0 && !eastDoor) {
		totalRooms--;
		east = new Room(xPos + 1, yPos, 1, east, mapArray);
		eastDoor = true;
	}
	if (roomLayout & 4 && totalRooms > 0 && !southDoor) {
		totalRooms--;
		south = new Room(xPos, yPos - 1, 2, south, mapArray);
		southDoor = true;
	}
	if (roomLayout & 8 && totalRooms > 0 && !westDoor) {
		totalRooms--;
		west = new Room(xPos - 1, yPos, 3, west, mapArray);
		westDoor = true;
	}


}

int Room::getRoomXLoc() {
	return xPos;
}

int Room::getRoomYLoc() {
	return yPos;

}

Room* Room::goNorth() {
	return north;
}

Room* Room::goEast() {
	return east;
}

Room* Room::goSouth() {
	return south;
}

Room* Room::goWest() {
	return west;
}

int Room::getDoors() {
	int layout = 0;
	if (northDoor) {
		layout = layout + 1;
	}
	if (eastDoor) {
		layout = layout + 2;
	}
	if (southDoor) {
		layout = layout + 4;
	}
	if (westDoor) {
		layout = layout + 8;
	}
	return layout;
}